import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreMemberAccountService extends BaseService<any> {
  private readonly logger = new Logger(CoreMemberAccountService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * addLog
   * 对应 PHP: CoreMemberAccountService_core::addLog()
   * 逻辑类型: undefined - undefined
   */
  async addLog(site_id: number, member_id: number, account_type: number, account_data: number, from_type: number, memo: number, related_id: number) {
    // 基于PHP真实逻辑: addLog
    // PHP原文: $member_model = new Member();         $member_account_log_model = new MemberAccountLog();         //账户检测         $member_info = $member_model->where([...
const member_model = this.memberService;
        const member_account_log_model = this.memberAccountLogService;
        //账户检测
        const member_info = member_model.where([
            [ 'member_id', '=', member_id ],
            [ 'site_id', '=', site_id )
        )).field(account_type  + ',' . account_type  + '_get"  + ', username, mobile, nickname').lock(true).find(];
        if (!member_info)) throw new BusinessException('MEMBER_NOT_EXIST');
        const account_new_data = round((float) member_info[ account_type ] + (float) account_data, 2];

        if (account_new_data < 0) {
            throw new BusinessException('ACCOUNT_INSUFFICIENT');
  }
}
